package com.theo.mapper;

import com.theo.entity.NewsInfo;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author 方涛
 * @since 2021-02-02
 */
@Repository
public interface NewsInfoMapper extends BaseMapper<NewsInfo> {

    int saveNewsInfo(NewsInfo newsInfo);

    int deleteNewsInfo(Integer id);

    int updateNewsInfo(Integer id);

    @Select("SELECT `news_id`,`news_title`,`news_content`,`city_name`,`create_time`,`user_name`\n" +
            "FROM `news_info` n INNER JOIN `city_info` c\n" +
            "ON c.`city_id`=n.`city_id`\n" +
            "ORDER BY `create_time` DESC")
    List<NewsInfo> queryAllNewsInfo();

    NewsInfo queryNewsInfoById(Integer id);

    @Select("SELECT * FROM `news_info` WHERE SUBSTR(`create_time`,1,10)=#{date}")
    List<NewsInfo> findAllByDate(String date);


}
